<?php

class ServicesController extends FController {
    
    public function actions() {
        return array(
            'captcha' => array(
                'class'       => 'CCaptchaAction',
                'backColor'   => 0xEFF0F0,
                'transparent' => false,
                'foreColor'   => 0x0dae4b,
                'height' => 30,
                'width' => 100,
            ),
        );
    }

    public function actionIndex() {
        $this->actionBenhAnDienTu();
    }
    
    public function actionBenhAnDienTu() {
        $this->render('benhAnDienTu', array(
            'data' => $this->getDetail(2),
        ));
    }
    
    public function actionThanhToanBaoHiem() {
        $this->render('thanhToanBaoHiem', array(
            'data' => $this->getDetail(2),
        ));
    }
    
    public function actionDatLichKham() {
        $form = new LichKhamForm('contact');
        
        if ( isset($_POST['LichKhamForm']) ) {
            $form->attributes = $_POST['LichKhamForm'];

            if ( $form->validate() ) {
                $mailObj  = new SendMail('', '', $form->renderHtml());
                $mailObj->subject = '[YKhoaTamAn.com] Đặt lịch khám ' . date('Y-m-d');

                if ( $mailObj->send() ) {
                    Yii::app()->user->setState('message', 'contact_sendmail_success');
                    $this->redirect('datLichKham');
                }
            }
        }
        $this->render('datLichKham', array(
            'data' => $this->getDetail(3),
            'form' => $form,
        ));
    }
    
    public function actionKhamBenhTaiNha() {
         $this->render('khamBenhTaiNha', array(
            'data' => $this->getDetail(4),
        ));
    }
    
    private function getDetail($id) {
        $model = new FNews();
        return $model->getDetail($id . '-pvw');
    }
}